import java.util.HashSet;
import java.util.Set;

public class project {
    boolean ret;
    public boolean canReach(int[] arr, int start) {
        int len=arr.length;
        boolean[] booleans=new boolean[len];
        dfs(arr,booleans,start);
        return ret;
    }
    public void dfs(int[] arr,boolean[] booleans,int index){
        if(ret){
            return;
        }
        if(index<0||index>=arr.length||booleans[index]){
            return;
        }
        booleans[index]=true;
        if(arr[index]==0){
            ret=true;
            return;
        }
        dfs(arr,booleans,index+arr[index]);
        dfs(arr,booleans,index-arr[index]);
    }






















    public String longestNiceSubstring(String s) {
        String str="";
        int len=s.length();
        for(int i=0;i<len-1;i++){
            for(int j=i+1;j<len;j++){
                if(j-i+1>str.length()&&inspect(s.substring(i,j+1))){
                    str=s.substring(i,j+1);
                }
            }
        }
        return str;
    }
    public boolean inspect(String str){
        Set<Character> set=new HashSet<>();
        for(char ch : str.toCharArray()){
            set.add(ch);
        }
        for(char ch : str.toCharArray()){
            char u=Character.toUpperCase(ch);
            char l=Character.toLowerCase(ch);
            if(!set.contains(u)||!set.contains(l)){
                return false;
            }
        }
        return true;
    }
}
